<template>
  <header class="header" :class="{ scrolled: isScrolled }">
    <div class="nav-container">
      <div class="logo">
        <i class="fas fa-bolt"></i>
        <span>{{ t('home') === 'Home' ? 'ElectroTech Pro' : '电器专家' }}</span>
      </div>
      
      <!-- 桌面端导航 -->
      <nav class="desktop-only">
        <ul class="nav-menu">
          <li><router-link to="/" @click="scrollToSection('home')">{{ t('home') }}</router-link></li>
          <li><a href="#products" @click="scrollToSection('products')">{{ t('products') }}</a></li>
          <li><a href="#ai-assistant" @click="scrollToSection('ai-assistant')">{{ t('aiAssistant') }}</a></li>
          <li><a href="#contact" @click="scrollToSection('contact')">{{ t('contact') }}</a></li>
        </ul>
      </nav>
      
      <!-- 移动端菜单按钮 -->
      <div class="mobile-controls">
        <button class="lang-switch" @click="toggleLanguage">
          <i class="fas fa-globe"></i> 
          <span>{{ getCurrentLang() === 'zh' ? 'EN' : '中文' }}</span>
        </button>
        <button class="mobile-menu-btn mobile-only" @click="toggleMobileMenu">
          <i class="fas" :class="showMobileMenu ? 'fa-times' : 'fa-bars'"></i>
        </button>
      </div>
    </div>
    
    <!-- 移动端导航菜单 -->
    <div class="mobile-nav" :class="{ active: showMobileMenu }">
      <ul class="mobile-nav-menu">
        <li><router-link to="/" @click="closeMobileMenu">{{ t('home') }}</router-link></li>
        <li><a href="#products" @click="scrollToSection('products')">{{ t('products') }}</a></li>
        <li><a href="#ai-assistant" @click="scrollToSection('ai-assistant')">{{ t('aiAssistant') }}</a></li>
        <li><a href="#contact" @click="scrollToSection('contact')">{{ t('contact') }}</a></li>
      </ul>
    </div>
  </header>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { useI18n } from '../composables/useI18n'

const { t, toggleLanguage, getCurrentLang } = useI18n()

const isScrolled = ref(false)
const showMobileMenu = ref(false)

const handleScroll = () => {
  isScrolled.value = window.scrollY > 100
}

const toggleMobileMenu = () => {
  showMobileMenu.value = !showMobileMenu.value
}

const closeMobileMenu = () => {
  showMobileMenu.value = false
}

const scrollToSection = (sectionId) => {
  closeMobileMenu()
  setTimeout(() => {
    const element = document.getElementById(sectionId)
    if (element) {
      element.scrollIntoView({ behavior: 'smooth' })
    }
  }, 100)
}

onMounted(() => {
  window.addEventListener('scroll', handleScroll)
})

onUnmounted(() => {
  window.removeEventListener('scroll', handleScroll)
})
</script>

<style scoped>
.header {
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  color: white;
  padding: 1rem 0;
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.header.scrolled {
  background: rgba(30, 60, 114, 0.95);
  padding: 0.5rem 0;
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
}

@media (min-width: 768px) {
  .nav-container {
    padding: 0 2rem;
  }
}

.logo {
  font-size: 1.5rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@media (min-width: 768px) {
  .logo {
    font-size: 1.8rem;
  }
}

.nav-menu {
  display: flex;
  list-style: none;
  gap: 1.5rem;
  align-items: center;
}

@media (min-width: 1024px) {
  .nav-menu {
    gap: 2rem;
  }
}

.nav-menu a {
  color: white;
  text-decoration: none;
  transition: all 0.3s ease;
  padding: 0.5rem 1rem;
  border-radius: 5px;
  font-size: 0.9rem;
}

@media (min-width: 1024px) {
  .nav-menu a {
    font-size: 1rem;
  }
}

.nav-menu a:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.mobile-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.lang-switch {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 25px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 0.8rem;
}

@media (min-width: 768px) {
  .lang-switch {
    font-size: 1rem;
  }
}

.lang-switch:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.mobile-menu-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  padding: 0.5rem;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 1.2rem;
}

.mobile-menu-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.mobile-nav {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: rgba(30, 60, 114, 0.98);
  backdrop-filter: blur(10px);
  transform: translateY(-100%);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.mobile-nav.active {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

.mobile-nav-menu {
  list-style: none;
  padding: 1rem;
}

.mobile-nav-menu li {
  margin-bottom: 0.5rem;
}

.mobile-nav-menu a {
  color: white;
  text-decoration: none;
  display: block;
  padding: 1rem;
  border-radius: 5px;
  transition: all 0.3s ease;
  font-size: 1.1rem;
}

.mobile-nav-menu a:hover {
  background: rgba(255, 255, 255, 0.1);
}
</style>
